****************************************************************
***** this do-file replicates the figures and tables in the main text
****************************************************************

cd "~/Wilfahrt_APSR Replication Data"

use "Data/APSR_Data_Final.dta", clear

grstyle init
grstyle set plain, horizontal grid dotted

ssc install coefplot

label var grid_perc_h20 "% Grid Water"
label var CHIRPS_Prec_mm "Prec (mm)"
label var landsuitability "Agr. Suitability"
label var elevation "Elevation (m)"
label var Rugged_RuggednessFinal "Terrain Ruggedness"
label var mt_binary_mean "Mountainous"
label var malaria_2000 "Malaria Suitability"
label var grid_longitude "Longitude"
label var grid_latitude "Latitude"
label var popdensity_0ad "Ecological Diversity"
label var NaturalResources_Dummy "Natural Resources"
label var D_Coast_km "D Coast (km)"
label var ln_d_coast_km "ln D Coast (km)"
label var Centralized_8hr "Atlas 8hr"
label var popdensity_0ad "Pop Density 0AD"
label var ln_popdensity_0ad "ln Pop Density 0AD"
label var Centralized_8hr "Centralized, 8hr"
label var Eco_Diversity "Eco. Diversity"
label var Min_D_State_Indep "D State Independence (km)"

global pretreatment ln_popdensity_0ad Eco_Diversity ln_d_coast_km NaturalResources_Dummy grid_perc_h20 landsuitability elevation Rugged_RuggednessFinal mt_binary_mean
global posttreatment Min_D_State_Indep ln_CHIRPS_Prec_mm malaria_2000 ln_dist_capital_km_pre2011 
global posttreatment_post2011 Min_D_State_Indep  ln_CHIRPS_Prec_mm malaria_2000 ln_dist_capital_km 

d $pretreatment
d $posttreatment 
d $posttreatment_post2011 

drop if Counterfactual == 0


*** FIGURE 4: Eﬀect of Statehood (8hr walk) on Conﬂict and Development Outcomes
{
* 4a. CONFLICT
reg ln_Agg_Acled_pre2013 Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ln_agAcled1
reg ln_Agg_Acled_pre2013 Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ln_agAcled2
reg ln_Agg_Acled_pre2013 Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store ln_agAcled3
	
coefplot (ln_agAcled1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(ln_agAcled2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(ln_agAcled3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick))),  ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("ln # Battles (Acled)", size(medlarge)) legend(off) /// 
	xlabel(-.01(.01).03) levels(95 90) ysize(8) xsize(4) plotregion(lcolor(black)) ///
	ylabel(.75 `" "OLS" "Base" "' 1 `" "OLS" "+ Pre" "Treatment" "' 1.25 `" "OLS" "+ Pre" "& Post" "Treatment" "') ///
	name("lnacled", replace) 

reg ln_N_yrs_conflict_Acled_pre2013 Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ln_YrsAcled1
reg ln_N_yrs_conflict_Acled_pre2013 Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ln_YrsAcled2
reg ln_N_yrs_conflict_Acled_pre2013 Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store ln_YrsAcled3
	
coefplot (ln_YrsAcled1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(ln_YrsAcled2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(ln_YrsAcled3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick))),  ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("ln Yrs Conflict (Acled)", size(medlarge)) legend(off) /// 
	xlabel(-.02(.02).08) levels(95 90) ysize(8) xsize(4) plotregion(lcolor(black)) ///
	ylabel("") ///
	name("lnyrsacled", replace) 	
	
reg ln_N_Battles_State_pre2013 Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnNBattle1
reg ln_N_Battles_State_pre2013 Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnNBattle2
reg ln_N_Battles_State_pre2013 Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store lnNBattle3
	
coefplot (lnNBattle1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(lnNBattle2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(lnNBattle3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick)))  , ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("ln # Battles (UCDP)", size(medlarge)) legend(off) /// 
	xlabel(-.01(.01).03) levels(95 90) ysize(8) xsize(4) plotregion(lcolor(black)) ///
	ylabel("") ///
	name("lnbattles", replace) 	

	
reg ln_N_StateConflicts_pre2013 Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnNConflict1
reg ln_N_StateConflicts_pre2013 Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnNConflict2
reg ln_N_StateConflicts_pre2013 Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store lnNConflict3
	
coefplot (lnNConflict1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(lnNConflict2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(lnNConflict3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick)))  , ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("ln # Conflicts (UCDP)", size(medlarge)) legend(off) /// 
	xlabel(-.01(.01).03) levels(95 90) ysize(8) xsize(4) plotregion(lcolor(black)) ///
	ylabel("") ///
	name("lnconflicts", replace) 	

reg ln_N_yrs_Stateconflict_pre2013 Centralized_8hr  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnyrsconflict1
reg ln_N_yrs_Stateconflict_pre2013 Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnyrsconflict2
reg ln_N_yrs_Stateconflict_pre2013 Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store lnyrsconflict3
	
coefplot (lnyrsconflict1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(lnyrsconflict2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(lnyrsconflict3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick))) , ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("ln Yrs Conflict (UCDP)", size(medlarge)) legend(off) /// 
	xlabel(-.01(.01).03) levels(95 90) ysize(8) xsize(4) plotregion(lcolor(black)) ///
	ylabel("") ///
	name("lnyrsconflict", replace) 		
	
graph combine lnacled lnyrsacled lnbattles lnconflicts lnyrsconflict, ///
	row(1) ysize(4) xsize(9)
	
* 4b. DEVELOPMENT
reg nightlight_20132_mean Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store nightlight1
reg nightlight_20132_mean Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store nightlight2
reg nightlight_20132_mean Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store nightlight3
	
coefplot (nightlight1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(nightlight2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(nightlight3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick)))  , ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("Mean Nightlights", size(medlarge)) legend(off) plotregion(lcolor(black)) /// 
	xlabel(-.2(.2).6) levels(95 90) ysize(8) xsize(4) ///	
	ylabel(.75 `" "OLS" "Base" "' 1 `" "OLS" "+ Pre" "Treatment" "' 1.25 `" "OLS" "+ Pre" "& Post" "Treatment" "') ///
	name("nightlight", replace) 

reg ln_mean2013 Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnnightlight1
reg ln_mean2013 Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnnightlight2
reg ln_mean2013 Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store lnnightlight3
	
coefplot (lnnightlight1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(lnnightlight2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(lnnightlight3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick)))  , ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("Mean Ln Nightlights", size(medlarge)) legend(off) plotregion(lcolor(black))  /// 
	xlabel(-.02(.02).06) levels(95 90) ysize(8) xsize(4) ///	
	ylabel("") name("lnnightlight", replace) 

reg rwi Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store rwi1
reg rwi Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store rwi2
reg rwi Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store rwi3
	
coefplot (rwi1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(rwi2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(rwi3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick))) , ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("RWI", size(medlarge)) legend(off) plotregion(lcolor(black)) /// 
	xlabel(-.02(.02).04) levels(95 90) ysize(8) xsize(4) ///	
	ylabel("") name("rwi", replace) 	

reg EWI_Index Centralized_8hr c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ewi1
reg EWI_Index Centralized_8hr $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ewi2
reg EWI_Index Centralized_8hr $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store ewi3
	
coefplot (ewi1, mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(ewi2, mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(ewi3, mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick))) , ///
	keep(Centralized_8hr) xline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("EWD", size(medlarge)) legend(off) plotregion(lcolor(black)) /// 
	xlabel(-.02(.02).04) levels(95 90) ysize(8) xsize(4) ///	
	ylabel("") ///
	name("ewd", replace) 
	
graph combine nightlight lnnightlight rwi ewd , ///
	row(1) 
}
	
	
*** FIGURE 5: Effects of Types of Precolonial Statehood on Conflict & Development 
{
* Figure 5a: CONFLICT
reg ln_Agg_Acled_pre2013 i.Polity_Type_8hr  $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id) 
est store ln_agAcled
reg ln_N_yrs_conflict_Acled_pre2013 i.Polity_Type_8hr  $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store ln_YrsAcled
reg ln_N_Battles_State_pre2013 i.Polity_Type_8hr  $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store lnNBattle
reg ln_N_StateConflicts_pre2013 i.Polity_Type_8hr  $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store lnNConflict
reg ln_N_yrs_Stateconflict_pre2013 i.Polity_Type_8hr  $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store lnYrsConflict

coefplot (ln_agAcled,  mcolor(black) msize(small) msymbol(square_hollow) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(ln_YrsAcled,  mcolor(black) msize(small) msymbol(circle_hollow) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(lnNBattle,  mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(lnNConflict,  mcolor(black) msize(small) msymbol(square) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(lnYrsConflict,  mcolor(black) msize(small) msymbol(circle) ciopts(lcolor(black black) lwidth(vthin medthick))) , ///
	drop(_cons  $pretreatment $posttreatment  grid_longitude grid_latitude c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2) vertical yline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("", size(medlarge)) /// 
	xlabel(1 "Federation" 2 "Gatekeeper" 3 "Regal" 4 "Despotic", labsize(small)) ylabel(-.05(.025).1) levels(95 90) ///
	legend(order(3 "Acled ln # Battles" 6 "Acled ln # Conflict Years" 9 "UCDP ln # Battles" 12 "UCDP ln # Conflicts" 15 "UCDP ln # Conflict Years") col(1) position(3) size(small)) ///
	name("Conflict", replace) 

* Figure 5b: DEVELOPMENT
reg nightlight_20132_mean i.Polity_Type_8hr  $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store Mean2013
reg ln_mean2013  i.Polity_Type_8hr  $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store ln_Mean2013
reg rwi i.Polity_Type_8hr  $pretreatment $posttreatment_post2011   c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store rwi
reg EWI_Index i.Polity_Type_8hr  $pretreatment $posttreatment_post2011   c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
est store ewi

coefplot (Mean2013,  mcolor(black) msize(small) msymbol(square) ciopts(lcolor(black black) lwidth(vthin medthick))) ///
	(ln_Mean2013,  mcolor(black) msize(small) msymbol(circle) ciopts(lcolor(black black) lwidth(vthin medthick)))  ///
	(rwi,  mcolor(black) msize(small) msymbol(diamond) ciopts(lcolor(black black) lwidth(vthin med)))  ///
	(ewi,  mcolor(black) msize(small) msymbol(triangle) ciopts(lcolor(black black) lwidth(vthin med))) , ///
	drop(_cons  $pretreatment $posttreatment $posttreatment_post2011  grid_longitude grid_latitude c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2) vertical yline(0, lcolor(gs8) lpattern(solid) lwidth(thin)) ///
	title("", size(medlarge)) /// 
	xlabel(1 "Federation" 2 "Gatekeeper" 3 "Regal" 4 "Despotic", labsize(small)) ylabel(-.5(.25).75) levels(95 90) ///
	legend(order(3 "Nightlight" 6 "ln Nightlight" 9 "Relative Wealth" 12 "EWI Index") col(1) position(3) size(small)) ///
	name("EconDev", replace) 
}
	

*** TABLE 2: State Type Model Results
{
reg ln_Agg_Acled_pre2013  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ln_agAcled2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg ln_Agg_Acled_pre2013  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store ln_agAcled3
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"
	
reg ln_N_yrs_conflict_Acled_pre2013  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ln_YrsAcled2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg ln_N_yrs_conflict_Acled_pre2013  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store ln_YrsAcled3
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

reg ln_N_Battles_State_pre2013  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnNBattle2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg ln_N_Battles_State_pre2013  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store lnNBattle3
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

reg ln_N_StateConflicts_pre2013  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnNConflict2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg ln_N_StateConflicts_pre2013  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store lnNConflict3
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

reg ln_N_yrs_Stateconflict_pre2013  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store lnYrsConflict2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg ln_N_yrs_Stateconflict_pre2013  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment  c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store lnYrsConflict3
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

esttab  ln_agAcled2 ln_agAcled3  ln_YrsAcled2 ln_YrsAcled3  lnNBattle2 lnNBattle3  lnNConflict2 lnNConflict3  lnYrsConflict2 lnYrsConflict3 using "Data/Table Output/Conflict_Type_All.tex", replace ///
	scalars(r2 "LL Geog. Coordinates" "CN Pretreatment controls" "PTCN Posttreatment controls") modelwidth(2) se b(3) star (* 0.1 ** 0.05 *** 0.001) drop(_cons $posttreatment  $pretreatment grid_longitude grid_latitude c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2) ///
	label title("Model Results"\label{Base_Conflict}) nonumbers compress  ///
	mtitles("ln Acled Battles" "ln ACLED Yrs Conflict" "ln UCDP Battles" "ln # UCDP Conflicts" "ln UCDP Yrs Conflict")
	

reg nightlight_20132_mean  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store Mean20132
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg nightlight_20132_mean  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store Mean20133
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

reg ln_mean2013  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ln_Mean20132
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg ln_mean2013  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store ln_Mean20133
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

reg rwi  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store rwi2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg rwi  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store rwi3
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

reg EWI_Index  Type_2 Type_3 Type_4 Type_5  $pretreatment c.grid_longitude##c.grid_latitude grid_longitude2 grid_latitude2, cluster(grid0_5_id)
	est store ewi2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  PTCN  "No"
reg EWI_Index  Type_2 Type_3 Type_4 Type_5 $pretreatment $posttreatment c.grid_longitude##c.grid_latitude  grid_longitude2 grid_latitude2,   cluster(grid0_5_id)
	est store ewi3
	estadd local  CN  "Yes"
	estadd local  LL  "Yes"
	estadd local  PTCN  "Yes"

	
esttab  Mean20132 Mean20133  ln_Mean20132 ln_Mean20133  rwi2 rwi3  ewi2 ewi3 using "Data/Table Output/Dev_Type_All.tex", replace ///
	scalars(r2 "LL Geog. Coordinates" "CN Pretreatment controls" "PTCN Posttreatment controls") modelwidth(2) se b(3) star (* 0.1 ** 0.05 *** 0.001) drop(_cons $posttreatment $pretreatment grid_longitude grid_latitude c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2) ///
	label title("Model Results"\label{Base_Dev}) nonumbers compress  ///
	mtitles("Mean Nightlights" "ln Mean Nightlights" "RWI" "EWD")
}	


*** TABLE 3: Characteristics of Precolonial Governance by State Type
{
import excel "Data/Atlas of 19th c Polities/Polity_Data.xlsx", firstrow clear

gen Polity_Type_8hr = .
replace Polity_Type_8hr = 1 if Elite_Structure == "Federation"
replace Polity_Type_8hr = 2 if Elite_Structure == "Gatekeeper" | Elite_Structure == "gatekeeper"
replace Polity_Type_8hr = 3 if Elite_Structure == "Regal"
replace Polity_Type_8hr = 4 if Elite_Structure == "Despotic"

drop if Polity == "Sokoto Emirates" | Polity == "Mossi States" | Polity == "Late Samory"  | Polity == "Adamawa Emirates"  | Polity == "Yoruba"

sum  Councilors  if  Polity_Type_8hr  == 1
sum  Councilors  if  Polity_Type_8hr  == 2
sum  Councilors  if  Polity_Type_8hr  == 3
sum  Councilors  if  Polity_Type_8hr  == 4

tab  Judicial_Autonomy  if  Polity_Type_8hr  == 1
tab  Judicial_Autonomy  if  Polity_Type_8hr  == 2
tab  Judicial_Autonomy  if  Polity_Type_8hr  == 3
tab  Judicial_Autonomy  if  Polity_Type_8hr  == 4

}


*** TABLE 4: Mechanisms: Evidence from the Afrobarometer
{
use "Data/APSR_Data_Final.dta", clear
sort grid_id
merge grid_id using "Data/Mechanisms/AB_Final.dta"
drop if _merge == 1

global pretreatment ln_popdensity_0ad Eco_Diversity landsuitability ln_d_coast_km NaturalResources_Dummy grid_perc_h20 elevation Rugged_RuggednessFinal mt_binary_mean
global posttreatment_AB Urban Education Poverty Min_D_State_Indep ln_CHIRPS_Prec_mm malaria_2000 ln_D_Capital_AB_km 

d $pretreatment
d $posttreatment_AB 

* a. Deference to Authority in Decision-Making
reg Vote_Pressure2 i.Polity_Type_8hr respAge age2 Female $pretreatment $posttreatment_AB c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2 grid_longitude grid_latitude i.Round , cluster(uniqueea)
	est store Vote1
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  DM  "Yes"
reg TradLead_Influence_Vote i.Polity_Type_8hr respAge age2 Female $pretreatment $posttreatment_AB c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2 grid_longitude grid_latitude i.Round , cluster(uniqueea)
	est store Vote2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  DM  "Yes"
reg  TradLead_StayOut_Politics i.Polity_Type_8hr respAge age2 Female $pretreatment $posttreatment_AB c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2 grid_longitude grid_latitude i.Round , cluster(uniqueea)
	est store Vote3
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  DM  "Yes"

* b. Out-Group Tolerance
reg Ethnic_Neighbors i.Polity_Type_8hr respAge age2 Female $pretreatment $posttreatment_AB c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2 grid_longitude grid_latitude i.Round , cluster(uniqueea)
	est store tolerance1
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  DM  "Yes"
reg Leaders_Equal_v_Grp i.Polity_Type_8hr respAge age2 Female $pretreatment $posttreatment_AB c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2 grid_longitude grid_latitude i.Round , cluster(uniqueea)
	est store tolerance2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  DM  "Yes"

* c. Tolerance for Violent Bargaining
reg Violence_justified i.Polity_Type_8hr respAge age2 Female $pretreatment $posttreatment_AB c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2 grid_longitude grid_latitude i.Round , cluster(uniqueea)
	est store Violence1
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  DM  "Yes"
reg Used_Pol_Violence i.Polity_Type_8hr respAge age2 Female $pretreatment $posttreatment_AB c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2 grid_longitude grid_latitude i.Round , cluster(uniqueea)
	est store Violence2
	estadd local  LL  "Yes"
	estadd local  CN  "Yes"
	estadd local  DM  "Yes"

esttab Vote1 Vote2 Vote3  tolerance1 tolerance2   Violence1 Violence2  using "Data/Table Output/Mech_AB_1.tex", replace ///
	scalars(r2 "Geo Coordinates" "CN Pretreatment controls" "DM Demographic controls") modelwidth(2) se b(3) drop(_cons respAge age2 Female $pretreatment $posttreatment_AB grid_longitude grid_latitude c.grid_longitude#c.grid_latitude grid_longitude2 grid_latitude2) ///
	star(* 0.10 ** 0.05 *** 0.001) label title("Mechanisms: Evidence from the Afrobarometer"\label{Mech_AB1}) nonumbers compress  ///
	mtitles("Vote Pressure" "Trad Leaders Influence Vote" "Trad Leaders Should Stay Out of Politics"  "Like Non-Co-Ethnic Neighbors"  "Leaders Favor Own Group" "Pol Violence Justified" "Used Pol Violence")



}

